# TODO: 直方图与散点图
# DATE: 2022/3/30
# AUTHOR: Cheng Ze WUST
import math
import random
import numpy as np
import matplotlib.pyplot as plt

data=np.random.normal(0,20,1000)
bins=np.arange(-100,100,5)
plt.hist(data,bins=bins)    #数据,坐标
plt.xlim([min(data)-5,max(data)+5])
plt.show()


data1=[random.gauss(15,10) for i in range(500)]
data2=[random.gauss(5,5) for i in range(500)]
bins=np.arange(-50,50,2.5)
plt.hist(data1,bins=bins,label='class 1',alpha=0.5)
plt.hist(data2,bins=bins,label='class 2',alpha=0.5)
plt.legend(loc='best')
plt.title('Fig2')
plt.show()


#region 散点图
mu_vecl=np.array([0,0])
cov_matl=np.array([[2,0],[0,2]])
x1_samples=np.random.multivariate_normal(mu_vecl,cov_matl,100)
x2_samples=np.random.multivariate_normal(mu_vecl+0.2,cov_matl+0.2,100)
x3_samples=np.random.multivariate_normal(mu_vecl+0.4,cov_matl+0.4,100)
plt.figure(figsize=(8,6))
#绘制散点图
plt.scatter(x1_samples[:,0],x1_samples[:,1],marker='x',color='blue',alpha=0.5,label='x1')
plt.scatter(x2_samples[:,0],x2_samples[:,1],marker='o',color='red',alpha=0.5,label='x2')
plt.scatter(x3_samples[:,0],x3_samples[:,1],marker='^',color='green',alpha=0.5,label='x3')
plt.legend(loc='best')
plt.title('Fig3')
plt.show()


x_coords=[0.13,0.22,0.39,0.56,0.68,0.74,0.93]
y_coords=[0.67,0.43,0.77,0.63,0.50,0.72,0.61]
plt.figure(figsize=(8,6))
plt.scatter(x_coords,y_coords,marker='o',s=50)
for x,y in zip(x_coords,y_coords):  #显示坐标值
    plt.annotate('(%s,%s)'%(x,y),xy=(x,y),xytext=(0,-15),textcoords='offset points',ha='center')
plt.title('Fig4')
plt.show()


mu_vecl=np.array([0,0])
cov_matl=np.array([[1,0],[0,1]])
X=np.random.multivariate_normal(mu_vecl,cov_matl,500)
fig=plt.figure(figsize=(8,6))
R=X**2
R_sum=R.sum(axis=1)
plt.scatter(X[:,0],X[:,1],color='grey',marker='s',s=20*R_sum,alpha=0.5)
plt.title('Fig5')
plt.show()
#endregion


